import axios from "axios";
import { useEffect, useState } from "react";
import { SidebarStaff } from "../../components/Sidebar";

export const StaffHome = () => {
    const [saRoleCheck, setSaRoleCheck] = useState(false);
    const userId = window.localStorage.getItem("userId");

    //check if staff is already logged in
    useEffect(() => {
        axios({
            method: 'GET',
            headers: { "satoken": window.localStorage.getItem("satoken") },
            url: 'http://localhost:8080/user/staff/home',
        })
        .then((res) => {
            if (res.data.success) {
                setSaRoleCheck(true);
            }
            else {setSaRoleCheck(false);}
        });
    }, []); // initial render


    if(saRoleCheck){
        return (
            <>
            <SidebarStaff />
            <div className="userProfile">
                <h3>Hello Staff User Id: {userId}!</h3>
            </div>
            </>
        )
    }
    else {
        return (
            <></>
        )
    }
}